package com.yuanfeng.base.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yuanfeng.base.entity.BaseReportEntity;
import com.yuanfeng.base.entity.BaseReportSubjectEntity;
import com.yuanfeng.base.entity.BaseReportTypeEntity;
import com.yuanfeng.base.mapper.BaseReportMapper;
import com.yuanfeng.base.mapper.BaseReportSubjectMapper;
import com.yuanfeng.base.mapper.BaseReportTypeMapper;
import com.yuanfeng.base.service.BaseReportService;
import com.yuanfeng.commoms.config.YFConfig;
import com.yuanfeng.commoms.exception.BizCodeEnume;
import com.yuanfeng.commoms.util.RedisUtil;
import com.yuanfeng.commoms.util.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 *
 */
@Service
public class BaseReportServiceImpl extends ServiceImpl<BaseReportMapper, BaseReportEntity>
    implements BaseReportService{

    @Autowired
    private BaseReportTypeMapper baseReportTypeMapper;
    @Autowired
    private BaseReportSubjectMapper baseReportSubjectMapper;
    @Override
    public ResponseResult queryReportMeassagePort(Map<String, Object> param) {
        Map<String, Object> map = new HashMap<String, Object>();
        if (RedisUtil.exists(YFConfig.YF_USER_TOKEN_USER + param.get("token").toString())) {

            String goodsName = this.baseMapper.queryReportGoodsName(Integer.valueOf( param.get("goodsId").toString()));
            List<BaseReportTypeEntity> type = baseReportTypeMapper.selectList(new LambdaQueryWrapper<BaseReportTypeEntity>());
            List<BaseReportSubjectEntity> subject = baseReportSubjectMapper.selectList(new LambdaQueryWrapper<BaseReportSubjectEntity>());
            map.put("goodsName", goodsName);
            map.put("type", type);
            map.put("subject", subject);
            map.put("goodsId", param.get("goodsId").toString());
        } else {
            return ResponseResult.fail(BizCodeEnume.INSUFFICIENT_PERMISSIONS);
        }
        return ResponseResult.success(map);
    }
}




